-
Notifications
You must be signed in to change notification settings - Fork 103
Lesson 49 (optional) #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: for-pr
Are you sure you want to change the base?
Lesson 49 (optional) #108
Conversation
| CarService carService = new CarService(initCars()); | ||
|
|
||
| Car desiredCar = createCar(); | ||
| Optional<Car> foundCar = carService.findCar(desiredCar); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Избыточная переменная
| String found = foundCar.map("Найдена машина:\n%s"::formatted) | ||
| .orElse("Подходящая машина не обнаружена"); | ||
|
|
||
| System.out.println(found); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно было впихнуть в ifPresentOrElse()
| .getYear() <= 2021) | ||
| .map(Car::getOwner) | ||
| .filter(person -> !person.getProfession() | ||
| .equals("policeman")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Конструкции с equals и константой/литералом зачастую лучше описывать в другом порядке:
"policeman".equals(person.getProfession())во избежание NPE на ровном месте
| .getYear() <= 2021) | ||
| .map(Car::getOwner) | ||
| .filter(person -> !person.getProfession() | ||
| .equals("policeman")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Конструкции с equals и константой/литералом зачастую лучше описывать в другом порядке:
"policeman".equals(person.getProfession())во избежание NPE на ровном месте
| .map(Home::getAddress) | ||
| .filter(address -> !address.contains("Рублевское шоссе")); | ||
|
|
||
| String address = foundAddress.map("Найден адрес:\n%s"::formatted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем отдельная переменная
| String address = foundAddress.map("Найден адрес:\n%s"::formatted) | ||
| .orElse("Адресс не найден"); | ||
|
|
||
| System.out.println(address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ifPresentOrElse()?
No description provided.